import { Component, OnInit }      from '@angular/core';
import { Device }                 from "@shared/model/device-dto";
import { ActivatedRoute, Router } from "@angular/router";
import { DeviceService }          from "../../manager/device/device.service";
import { Observable }             from "rxjs";

@Component({
    selector   : 'app-device-view',
    templateUrl: './view.component.html',
})
export class DeviceViewComponent implements OnInit
{
    device$: Observable<Device>;
    deviceId = this.route.snapshot.params.id;
    menus: any[] = [
        {
            key  : 'info',
            title: '设备信息',
        },
        {
            key  : 'replenishment',
            title: '补货记录',
        },
        {
            key  : 'bonus',
            title: '分成设置',
        },
        {
            key  : 'log',
            title: '事件日志',
        },
    ];
    
    
    constructor( private deviceService: DeviceService,
                 private route: ActivatedRoute,
                 private router: Router, )
    {
    }
    
    ngOnInit()
    {
        this.device$ = this.deviceService.load(this.deviceId);
    }
    
    to( item )
    {
        this.router.navigateByUrl(`/device/view/${ item.key }/${ this.deviceId }`);
    }
}
